/**
 * 功能描述 导航栏
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var enmu = require("enums");
	var aw = require("ajaxwrapper");
	var store =require("store");
	var activeUser = store.get("user");	
	var intentionregister_Props = require("../constant/returnvisit_Props");
	var intentionRegisterSubnav_Events = require("../handler/ReturnvisitSubnav_Events");
	
    var instance = {
        initComponent: function (params, widget) {
        	var subnav=new Subnav({
        		parentNode:".J-subnav",
				model : {
					title:"签约回访",
					items : [{
						id : "search",
						type : "search",
						placeholder:"会员/合同号",
						handler : function(str){
							var grid = widget.get("grid");
							var obj = {
									s:str,
									"signUpDate":widget.get("subnav").getValue("checkInDate").start,
	                				"signUpDateEnd":widget.get("subnav").getValue("checkInDate").end,
	                				"visitStatus":widget.get("subnav").getValue("status"),
	                				"servicePoint":activeUser.servicePoint.pkServicePoint,
	                				"status":"Valid",
	    	     					fetchProperties:intentionregister_Props.gridFetchProperties
							};
							aw.ajax({
								url:"api/travelcontract/search",
								data:obj,
								dataType:"json",
								success:function(data){
									grid.setData(data);
								}
							});
						}
					},{
					      id:"status",
					      type : "buttongroup",
					      all:{
					       show:true,
					       first:true
					      },
					      tip:"回访状态",
					      items:enmu["com.eling.elcms.travel.model.TravelContract.VisitStatus"],
					      handler:function(key,element){
					    	  widget.get("grid").refresh();
					      }
					}, {
			            id: "checkInDate",
						tip:"签约日期",
						type:"daterange",
						ranges : {
							"今天": [moment().startOf("days"),moment().endOf("days")],
					        "本月": [moment().startOf("month"), moment().endOf("month")],
					        "本年": [moment().startOf("year"), moment().endOf("year")]
						},
						defaultRange : "本月",
						handler : function(time){
							 widget.get("grid").refresh();
						}
			        },{
						id : "save",
						type : "button",
						text:"保存",						
						show : false,
						handler:function(){
							intentionRegisterSubnav_Events.save(widget);
						}
					},{
						id : "return",
						type : "button",
						text:"返回",						
						show : false,
						handler:function(){
							widget.show([".J-grid"]).hide([".J-tab", ".J-recordgrid"]);
							widget.get("subnav").show(["checkInDate","status","search"]).hide(["return","save"]);							
							widget.get("grid").refresh();
						}
					}]
				}
        	});
        	widget.set("subnav",subnav);
        }
    };
    module.exports = instance;
});
